<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <title>回调函数的ref</title>
</head>

<body>
    <!-- 准备好一个容器 -->
    <div id="test"></div>


    <!-- 引入react核心库 -->
    <script type="text/javascript" src="../js/react.development.js"></script>
    <script type="text/javascript" src="../js/react-dom.development.js"></script>
    <script type="text/javascript" src="../js/babel.min.js"></script>

    <script type="text/babel">  /*此处一定要写babel*/
        //创建组件
        class Demo extends React.Component {

            state = {isHot:true};

            showInfo = () =>{
                const {input1} = this
                alert(input1.value)
            }

            changeWeather = ()=>{
                const {isHot} = this.state;
                this.setState({isHot:!isHot})
            }

            saveInput=(cNode)=>{
                this.input1=cNode;
                console.log('@',cNode);
            }

            render() {
                const {isHot} = this.state;
                return (
                    <div>
                        <h2>今天天气很{isHot?'炎热':'凉爽'}</h2>
                         {/*<input ref={(cNode)=>{this.input1=cNode;console.log('@',cNode);}} type="text"  /><br/>*/}
                         <input ref={this.saveInput} type="text"  /><br/>
                        <button onClick={this.showInfo}>点击提示输入数据</button>
                        <button onClick={this.changeWeather}>点我切换天气</button>
                    </div>
                )
            }
        }

        //渲染组件到页面
        ReactDOM.render(<Demo />, document.getElementById('test'));
    </script>
</body>

</html>